<!--#include file="../nav/admin_top.php" -->
<style type="text/css">
 
</style>
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">配送明细</span>
		<span class="totalSpan"> <label id="captionNum"></label> </span>
	</div>
</div>
<div style="margin:15px auto">
	搜索：
	<select id="status" class="textBox" style="margin-right:40px;">
		<option value="">-- 所有配送批次状态 --</option>
		<option value="0">计划中</option> 
		<option value="1">生产中</option> 
		<option value="2">已完成</option>
	</select> 
	<select id="senddate" class="textBox"  onChange="fnSearchDate()" style="margin-right:5px;">
		<option value="0" selected="selected">--所有配送批次日期--</option>
		<option value="1">今天</option> 
		<option value="2">本周</option> 
		<option value="3">本月</option> 
		<option value="">自定义时间段</option> 
	</select>
	<span id="s_date_div" style="display:none;margin:5px auto;">
		从 <input type="text" class="textBoxDate" id="b_date" value=""   maxlength="10" />
		<input id="b_date_slt" class="btnicon_calendar" type="button">
		到
		<input type="text" class="textBoxDate" id="e_date" value=""   maxlength="10" />
		<input id="e_date_slt" class="btnicon_calendar" type="button">
	</span>	
	
	<span style="margin-left:40px;">
		<input type="text" maxlength="12" id="keywords" class="searchs" /> 
		<input type="button"  onclick="fnSearchs()" value="查询"  />  	
	</span>	
</div> 
<div id="grids"></div> 
<script type="text/javascript">
var url_list = '/admin_send/index';
var url_modify = '/admin_send/modify';


$().ready(function(){
	o2js.build('ymprompt'); 

	o2js.build('jscalendar');
	o2js.build('dates');
	fnSetSltDate('b_date','b_date_slt')
	fnSetSltDate('e_date','e_date_slt')
	$('#b_date').val(getWeekFirst(new Date()).eformat('yyyy-MM-dd'));
	$('#e_date').val(getWeekLast(new Date()).eformat('yyyy-MM-dd'));
	$('#b_date').val('');
	$('#e_date').val('');


	o2js.build('jquery_cluetip');
	o2js.build('o2grid');
	showLoading();
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		cols:[
			{index:'id',mapping:'a.id', name:'序号', width:35,sortable:false, func:function(val,row_index,column_name,json,R){
				 return  '<span title="ID：'+json.id+'" >'+((R.page - 1)*R.rowNum + (row_index+1))+'</span>';
			}}, 
			{index:'code',mapping:'b.code', name:'配送批次', width:90,func:function(val,row_index,column_name,json,R){
					return '<a href="/admin_sendpi/view?id='+json.sendpi_id+'" target="_blank" >'+val+'</a>';
				}
			},
			{index:'senddate',mapping:'b.senddate', name:'配送日期', width:75 
			},
			{index:'status',mapping:'b.status', name:'批次状态', width:60 ,func:function(val,row_index,column_name,json,R){
					if(val == '0'){
						return  '<span class=" ">计划中</span>';
					}else if(val == '1'){
						return  '<span class="red">生产中</span>';
					}else{
						return '<span class="green">已完成</span>';
					}
			}
			},
			{index:'fenzhi_name',mapping:'d.name', name:'分支标识', width:80
			},
			{index:'username',mapping:'c.username', name:'会员编号', width:60 
			},
			{index:'name',mapping:'c.name', name:'会员姓名', width:60 
			},
			{index:'packet',mapping:'a.packet', name:'配送菜品', width:330 ,func:function(val,row_index,column_name,json,R){
				return json.veges_html;
			}
			}, 
			{index:'id',mapping:'a.id', name:'操作'	, width:70,sortable:false,func:function(val,row_index,column_name,json,R){
					var s = '';
					if(json.status=='0'){
						s += ' <a href="javascript:void(0)" onclick="fnModifySendVege('+json.id+')" ><img src="/misc/images/edit.gif" />修改选菜</a>';
					}else if(json.status=='1'){
						s += ' <a href="javascript:void(0)" class="notclick" onclick="alert(\'不能修改生产中的配送！\')" ><img src="/misc/images/edit.gif" />修改选菜</a>';
					}else{
						s += ' <a href="javascript:void(0)" class="notclick" onclick="alert(\'不能修改已完成的配送！\')" ><img src="/misc/images/edit.gif" />修改选菜</a>';
					}
					return s;
				}
			}
		]
	});
	fnSearchs();	 
	$('#keywords').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnSearchs();
		}
	}); 
	
});
function fnSearchs(){
	grids.setBaseParams({
		keywords:encodeURIComponent($('#keywords').val()),
		status:$('#status').val(),
		b_date:$('#b_date').val(),
		e_date:$('#e_date').val()
	}); 
	grids.load(1); 
}

/* 预定义日期 */
function fnSearchDate(){
	$('#s_date_div').hide();
	var date = new Date();
	switch($('#senddate').val()){
		case "0"://  
			$('#b_date').val('');
			$('#e_date').val('');
			break;
		case "1"://  
			$('#b_date').val(today());
			$('#e_date').val(today());
			break;
		case "2":// 
			var b = getWeekFirst(date).eformat('yyyy-MM-dd');
			var e = getWeekLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		case "3"://本月
			var b = getMonthFirst(date).eformat('yyyy-MM-dd');
			var e = getMonthLast(date).eformat('yyyy-MM-dd'); 
			$('#b_date').val(b);
			$('#e_date').val(e);
			break;
		default:
			$('#s_date_div').show();
			break;
	}
}

/* 修改基本信息 */
function fnModifySendVege(id){
	ymPrompt.close();
	ymPrompt.win({
		title:'修改选菜',
		fixPosition:true,
		maxBtn:true,
		width: 700, 
		height: 450,
		iframe:{
			src:url_modify+'?id='+id+'&endfunc=fnModifySendVegeEnd'
		}
	});
}
function fnModifySendVegeEnd(){
	grids.reload();
}
 
</script>
<!--#include file="../nav/admin_bottom.php" -->